package com.xuecheng.content.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xuecheng.base.exception.XueChengPlusException;
import com.xuecheng.content.model.po.CourseTeacher;
import com.xuecheng.content.service.CourseTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("课程教师关系接口")
@RestController
@RequestMapping("/courseTeacher")
public class CourseTeacherController {
    @Autowired
    CourseTeacherService courseTeacherService;

    @ApiOperation("查询课程对应的所有教师")
    @GetMapping("/list/{courseId}")
    public List<CourseTeacher> listTeacher(@PathVariable Long courseId){
        if(courseId == null){
            XueChengPlusException.cast("课程id为空");
        }
        return courseTeacherService.list(new LambdaQueryWrapper<CourseTeacher>()
                .eq(CourseTeacher::getCourseId,courseId));
    }

    @ApiOperation("新增课程教师")
    @PostMapping
    public CourseTeacher saveCourseTeacher(@RequestBody CourseTeacher courseTeacher){
        if(courseTeacher == null){
            XueChengPlusException.cast("传入的教师不能为空");
        }
        Long companyId = 1232141425L;
        return courseTeacherService.saveCourseTeacher(companyId,courseTeacher);
    }

    @ApiOperation("删除课程教师")
    @DeleteMapping("/course/{courseId}/{id}")
    public void deleteCourseTeacher(@PathVariable("courseId")Long courseId,
                                    @PathVariable("id") Long id){
        Long companyId = 1232141425L;
        courseTeacherService.checkCourseAndCompany(companyId,courseId);
        courseTeacherService.removeById(id);
    }
}
